package handin07;

import java.util.ArrayList;

public class Club implements IClub {
	
	private String name;
	private ArrayList<IMember> members;
	private ArrayList<IEmployee> staff;
	private ArrayList<IActivity> activities;
	
	public Club(String name) {
		this.name = name;
		members = new ArrayList<IMember>();
		staff = new ArrayList<IEmployee>();
		activities = new ArrayList<IActivity>();
	}


	public String getName() {
		return this.name;
	}


	@Override
	public ArrayList<IEmployee> getStaff() {
		return staff;
	}


	@Override
	public void addStaff(IEmployee person) {
		staff.add(person);
	}


	@Override
	public String getSalaries() 
	{
		String Salaries = "";
		for(IEmployee employee : staff){
			Salaries += employee.getName() + ": ";
			Salaries += employee.getSalary() + "\n";
		}
		return Salaries;
	}


	@Override
	public ArrayList<IMember> getMembers() {
		return members;
	}


	@Override
	public void addMember(IMember member) {
		members.add(member);
	}
	
	public ArrayList<IMember> getMembersByMembershipPlan(MembershipPlan plan)
	{
		ArrayList<IMember> returnValue = new ArrayList<IMember>();
		for(IMember m: members){
			if(m.getMembership().getMembershipPlan() == plan){
				returnValue.add(m);
			}
		}		
		return returnValue;
	}
	
	public ArrayList<IMember> getMembersBySport(IActivity activity)
	{
		ArrayList<IMember> returnValue = new ArrayList<IMember>();
		for(IMember m: members){
			for(IActivity a: m.getSports()){
				if(a.getName().equals(activity.getName())){
					returnValue.add(m);
				}
			}			
		}		
		return returnValue;
	}


	@Override
	public String getMemberFees() {
		String returnValue = "";
		for(IMember m: members){
			returnValue += ((AbstractPerson) m).getName() + ", ";
			returnValue += m.getMonthlyFee() + "\n";
		}		
		return returnValue;
	}	
	
	@Override
	public boolean addActivity(String name, double price, IEmployee trainer) {
		if(!activityExists(name)){
			IActivity activity = new Activity(name, price, trainer);
			activities.add(activity);
		}
		return false;
	}

	@Override
	public IActivity getActivity(String name) {
		IActivity activity = null;
		for(IActivity a : activities){
			if(a.getName().equalsIgnoreCase(name)){
				activity = a;
				break;
			}
		}
		return activity;
	}
	
	public ArrayList<IActivity> getActivityByInstructor(IEmployee instructor)
	{
		ArrayList<IActivity> returnedActivities = new ArrayList<IActivity>();
		for(IActivity a: activities){
			if(a.getTrainer() == instructor){
				returnedActivities.add(a);
			}
		}
		return returnedActivities;
	}
	
	private boolean activityExists(String name)
	{
		for(IActivity a : activities){
			if(a.getName().equalsIgnoreCase(name)){
				return true;
			}
		}	
		return false;
	}
	
}